//
//  WeaponViewController.m
//  MilitaryDemo
//
//  Created by qianfeng01 on 15-7-7.
//  Copyright (c) 2015年 qianfeng01. All rights reserved.
//

#import "WeaponViewController.h"
#import "WeaponCell1.h"
#import "FirstModel.h"
#import "WeaponDatabase.h"
#import "WeaponPicViewController.h"
@interface WeaponViewController ()<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>
@property(nonatomic,strong)UICollectionView *collectionView;
@end

@implementation WeaponViewController

- (void)viewDidLoad {
    [super viewDidLoad];
   // self.view.backgroundColor=[UIColor whiteColor];
    [self creatCollectionView];
    [self initModel];
}
-(void)initModel
{
    self.dataArr=[[WeaponDatabase sharedManager]selectAll];
    
    [self.collectionView reloadData];
}
-(void)creatCollectionView
{
    UICollectionViewFlowLayout *flowLayout=[[UICollectionViewFlowLayout alloc]init];
    [flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];
    // 对于垂直滚动，上下cell的间距，对于水平滚动，左右cell的间距 最小间距
    flowLayout.minimumLineSpacing = 10;
    // 设置item之间间距，实际间隔需要根据item的size和edgesInsets的值来调节
    flowLayout.minimumInteritemSpacing = 3;
    // 全局设置itemSize
    flowLayout.itemSize = CGSizeMake(kScreenSize.width/4, 100);
    
    // 内边距
    flowLayout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
    _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(20, 0, kScreenSize.width-40, kScreenSize.height-64) collectionViewLayout:flowLayout];
    _collectionView.delegate = self;
    _collectionView.dataSource = self;
    self.collectionView.backgroundColor=[UIColor whiteColor];
    [_collectionView registerNib:[UINib nibWithNibName:@"WeaponCell1" bundle:nil] forCellWithReuseIdentifier:@"WeaponCell1"];
    [self.view addSubview:_collectionView];
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.dataArr.count;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    WeaponCell1 *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"WeaponCell1" forIndexPath:indexPath];
    FirstModel *model=self.dataArr[indexPath.row];
    NSString *str=[NSString stringWithFormat:@"%@.jpg",model.des];
    cell.iconImageView.image=[UIImage imageNamed:str];
    cell.titleLabel.text=model.title;
    return cell;
    
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    FirstModel *model=self.dataArr[indexPath.row];
    WeaponPicViewController *picController=[[WeaponPicViewController alloc]init];
    picController.des=model.des;
   picController.hidesBottomBarWhenPushed=YES;
    [self.navigationController pushViewController:picController animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
